home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Blender 2.49b / blender-2.49b-windows.exe / $_4_ / .blender / scripts / textplugin_functiondocs.py < prev    next >
Text File  |  2009-08-31  |  1KB  |  65 lines

  1. #!BPY
  2. """
  3. Name: 'Function Documentation | Ctrl I'
  4. Blender: 246
  5. Group: 'TextPlugin'
  6. Shortcut: 'Ctrl+I'
  7. Tooltip: 'Attempts to display documentation about the function preceding the cursor.'
  8. """
  9.  
  10. # Only run if we have the required modules
  11. try:
  12.     import bpy
  13.     from BPyTextPlugin import *
  14. except ImportError:
  15.     OK = False
  16. else:
  17.     OK = True
  18.  
  19. def main():
  20.     txt = bpy.data.texts.active
  21.     if not txt:
  22.         return
  23.     
  24.     (line, c) = current_line(txt)
  25.     
  26.     # Check we are in a normal context
  27.     if get_context(txt) != CTX_NORMAL:
  28.         return
  29.     
  30.     # Identify the name under the cursor
  31.     llen = len(line)
  32.     while c<llen and (line[c].isalnum() or line[c]=='_'):
  33.         c += 1
  34.     
  35.     targets = get_targets(line, c)
  36.     
  37.     # If no name under cursor, look backward to see if we're in function parens
  38.     if len(targets) == 0 or targets[0] == '':
  39.         # Look backwards for first '(' without ')'
  40.         b = 0
  41.         found = False
  42.         for i in range(c-1, -1, -1):
  43.             if line[i] == ')': b += 1
  44.             elif line[i] == '(':
  45.                 b -= 1
  46.                 if b < 0:
  47.                     found = True
  48.                     c = i
  49.                     break
  50.         if found: targets = get_targets(line, c)
  51.         if len(targets) == 0 or targets[0] == '':
  52.             return
  53.     
  54.     obj = resolve_targets(txt, targets)
  55.     if not obj: return
  56.     
  57.     if isinstance(obj, Definition): # Local definition
  58.         txt.showDocs(obj.doc)
  59.     elif hasattr(obj, '__doc__') and obj.__doc__:
  60.         txt.showDocs(obj.__doc__)
  61.  
  62. # Check we are running as a script and not imported as a module
  63. if __name__ == "__main__" and OK:
  64.     main()
  65.